import cv2 as cv
import numpy as np

# 先进行锐化
def sharpen(gray):
    kernel_sharpen = np.array([
                [-0.5, -0.5, -0.5],
                [-0.5, 5, -0.5],
                [-0.5, -0.5, -0.5]])   # 参数可以修改
    output = cv.filter2D(gray, -1, kernel_sharpen)
    return output

# 正规化
def normalization_strength(gray):
    Imin, Imax = cv.minMaxLoc(gray)[:2]
    # Imax = np.max(img)
    # Imin = np.min(img)
    Omin, Omax = 0, 255
    # 计算a和b的值
    a = float(Omax - Omin) / (Imax - Imin)
    b = Omin - a * Imin
    out = a * gray + b
    out = out.astype(np.uint8)
    return out

# 线性
def linear_strength(gray):
  out = 2.0 * gray  # 该系数可以进行调整
  out[out > 255] = 255
  out = np.around(out)
  out = out.astype(np.uint8)
  return out

# gamma增强
def gamma_strength(gray):
  fi = gray / 255.0  # 图像归一化
  gamma = 0.8  # 该参数可以调整，越接近一，则差异化越小
  out = np.power(fi, gamma)
  return out